package com.popcorn.rmsystem.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.popcorn.action.Action;
import com.popcorn.action.ActionForward;
import com.popcorn.rmsystem.dao.RMSystemDAO;
import com.popcorn.rmsystem.model.RMSystemModel;

public class ReservationAddAction implements Action {

	@Override
	public ActionForward execute(HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		RMSystemDAO rmsDAO = new RMSystemDAO();
		RMSystemModel rmsModel = new RMSystemModel();
		ActionForward forward = new ActionForward();

		int STARTTIME = Integer.parseInt(request.getParameter("STARTTIME"));
		int ENDTIME = Integer.parseInt(request.getParameter("ENDTIME"));
   		boolean result=false;
   		
   		try{	
  			
   			String HP = request.getParameter("HP1")+
   					'-'+request.getParameter("HP2")+
   					'-'+request.getParameter("HP3");
   			
   			String rDATE = request.getParameter("TRANDATE");
   			String [] DATE = rDATE.split("-");
   			
   			rmsModel.setTEAM_NAME(request.getParameter("TEAM_NAME"));
   			rmsModel.setNAME(request.getParameter("NAME"));
   			rmsModel.setHP(HP);
   			rmsModel.setTRANDATE(DATE[0]+DATE[1]+DATE[2]);
   			rmsModel.setSTARTTIME(STARTTIME);
   			rmsModel.setENDTIME(ENDTIME);
   			rmsModel.setROOMSIZE(request.getParameter("ROOMSIZE"));
	   		result=rmsDAO.modelInsert(rmsModel);

			System.out.println("====================AddAction====================");
			System.out.println("2 : "+request.getParameter("TEAM_NAME"));
			System.out.println("3 : "+request.getParameter("NAME"));
	   		System.out.println("4 : "+request.getParameter("TRANDATE"));
	   		if(result==false){
	   			System.out.println("DB 등록 실패");
	   			return null;
	   		}
	   		System.out.println("DB 등록 성공");
	   		
	   		forward.setRedirect(true);
	   		forward.setPath("RMSListDB.bo"); 
	   		return forward;
	   		
  		}catch(Exception ex){
   			ex.printStackTrace();
   		}
		
		return null;
	}

}
